<!-- MenuComponent.vue -->
<template>
    <div v-for="item in menuList" :key="item.path || item.name" v-show="item.visible !== 1" class="menu-item">
        <!-- 叶子节点 -->
        <el-menu-item v-if="!item.children || item.children.length == 0" :index="item.path || ''">
            <el-icon v-if="item.icon">
                <component :is="item.icon" />
            </el-icon>
            <span>{{ item.name }}</span>
        </el-menu-item>

        <!-- 非叶子节点 -->
        <el-sub-menu v-else :index="item.path || item.name">
            <template #title>
                <el-icon v-if="item.icon">
                    <component :is="item.icon" />
                </el-icon>
                <span>{{ item.name }}</span>
            </template>
            <!-- 递归调用自身 -->
            <menu-component :menu-list="item.children" />
        </el-sub-menu>
    </div>
</template>

<script lang="ts" setup>
defineProps<{
    menuList: Array<MenuItem>;
}>();

export interface MenuItem {
    name: string;
    path?: string;
    icon?: string;
    menuType?: number;
    query?: string;
    visible?: number;
    children?: MenuItem[];
}

</script>

<style scoped lang="scss">
.menu-item {
    ::v-deep .el-sub-menu {
        .el-sub-menu__title:hover {
            background-color: hsl(from var(--menu-aside-bg-color) h s calc(l * 0.8)) !important;
        }
    }

    .el-menu-item:hover {
        background-color: hsl(from var(--menu-aside-bg-color) h s calc(l * 0.8)) !important;
    }
}
</style>